import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @author zhu
 * @date 2024-04-02
 */
public class MainTest {
    public static int sum(int num){
        Class<Math> clazz = Math.class;
        Method getSum = null;
        try {
            getSum = clazz.getMethod("getSum", int.class);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
        Parameter[] parameters = getSum.getParameters();
        for (Parameter parameter : parameters) {
            boolean isPresent = parameter.isAnnotationPresent(SetValue.class);
            if (isPresent){
                Annotation[] annotations = parameter.getAnnotations();
                for (Annotation annotation : annotations){
                    if (annotation instanceof SetValue){
                        SetValue mathAnnotation = (SetValue)annotation;
                        int value = mathAnnotation.value();
                        if (value < num){
                            throw new RuntimeException("超出了参数上限");
                        }
                    }
                }
            }
        }

        int sum = new Math().getSum(num);
        return sum;
    }
    public static void main(String[] args) {
        System.out.println(sum(101));
    }
}
